<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\BaseController;
use think\App;
use think\Request;

class Base extends BaseController
{
    use \liliuwei\think\Jump;
    public function __construct(App $app)
    {
        parent::__construct($app);
    }

    protected function objToArray($obj) //统一的对象转数组
    {
        return json_decode(json_encode($obj),true);
    }

    public function insertTime($data)    //统一的加入修改删除时间
    {
        $data['create_time'] = date("Y-m-d H:i:s");
        $data['update_time'] = date("Y-m-d H:i:s");

        return $data;
    }

    public function haveUpFile($name,$file)    //统一判断是否上传了文件  参数1 文件name 2 $_FILE 常量
    {
        if(!empty($file[$name]["name"])){
            $file = request()->file($name);
            $img_url = \think\facade\Filesystem::disk('public')->putFile( $name, $file);
            $cate_logo = "/storage/".$img_url;

            return $cate_logo;
        }
        return false;
    }
}
